package eleven;

import java.util.*;

public class SetDemo {
    public static void main(String[] args) {
//小面试题:如何去重?
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        list.add("two");
        Collections.sort(list, new Comparator<String>() {
            public int compare(String o1, String o2) {
            return o1.length()-o2.length();
            }
        });
        System.out.println("list:"+list); //[one, two, three, four, five, two]
        Set<String> set = new HashSet<>();
        set.addAll(list); //将list集合元素都添加到set集合中

        System.out.println("set:"+set); //[four, one, two, three, five]
    }
}

